<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<!DOCTYPE html>
<html>
<head>
    <title>代码管理</title>
    <script type="text/javascript">

        //代码类别查询
        function refreshTable() {
            var codeTypeId = $("#refreshTypeId").val();
            var codeTypeName = $("#refreshTypeName").val();
            $.post("${absoluteContextPath}/system/codeType/ajaxList", {
                'codeTypeId': codeTypeId,
                'codeTypeName': codeTypeName
            }, function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $("#tableContent").html(data.content.data);
                    var codeTypeIds = new Array();
                    $("#tableContent").find("tbody tr").each(function () {
                        codeTypeIds.push($(this).find(":eq(0)").html());
                    });
                    refreshTableInfo(codeTypeIds);
                } else {
                    $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
                }
            });
        }

        //查询代码信息
        function refreshTableInfo(codeTypeIds) {
            $.post("${absoluteContextPath}/system/codeInfo/ajaxList", {
                'codeTypeIds': codeTypeIds.toString()
            }, function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $("#tableContents").html(data.content.data);
                } else {
                    $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
                }
            });
        }
        //新增 编辑代码信息
        function popAddOrModifyInfo(id) {
            var codeTypeId = $("#selectTypeId").val();
            var data = {};
            var url = '${absoluteContextPath}/system/codeInfo';
            if (id != undefined) {
                data.id = id;
                url = url + "/goEdit";
            } else {
                if (codeTypeId) {

                    url = url + "/goAdd";
                } else {
                    $.showMessage({parentId: "showMessage", message: "请选择一条代码类别！", type: "error"});
                }
            }
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }

        //删除代码信息
        function deleteCodeInfo() {
            var i = 0;
            $("input[name=infoids]").each(function () {
                if ($(this).prop("checked")) {
                    i++;
                }
            });
            if (i == 0) {
                $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
                return false;
            } else {
                $.confirm({
                    confirm: function () {
                        var values = "";
                        $("input[name=infoids]").each(function () {
                            if ($(this).prop("checked")) {
                                values += $(this).val() + ",";
                            }
                        });
                        $("#confirmModal").modal("hide");
                        $.post("${absoluteContextPath}/system/codeInfo/delete", {
                            'ids': values
                        }, function (data) {
                            data = JSON.parse(data);
                            if (data.returnCode == 1) {
                                $.showMessage({parentId: "showMessage", message: "代码信息数据删除成功！", type: "success"});
                                refreshTable();
                            } else {
                                $.showMessage({parentId: "showMessage", message: "代码信息数据删除异常！", type: "error"});
                            }
                        });
                    }
                });
            }
        }
    </script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">系统管理</a></li>
        <li class="active">代码管理</li>
    </ol>
</div>

<div class="main">
    <!-- row -->
    <div class="row">
        <div class="col-md-12">
            <section class="tile">
                <!-- tile body -->
                <div class="tile-body">
                    <div id="showMessage"><#include "../../message.ftl" /></div>
                    <div class="form-horizontal">
                        <form id="search_codeType_table" action="${absoluteContextPath}/system/codeType/list"
                              method="post">
                            <input type="hidden" name="pageSize" value="${codeTypesTable.page.pageSize}"/>
                            <input type="hidden" name="currentPage" value="${codeTypesTable.page.currentPage}"/>


                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-5 control-label" for="exampleInputEmail2">代码类别ID</label>

                                    <div class="col-sm-7">
                                        <input class="form-control" name="codeTypeId" id="refreshTypeId" value=""
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-5 control-label" for="exampleInputEmail2">代码类别名称</label>

                                    <div class="col-sm-7">
                                        <input class="form-control" name="codeTypeName" id="refreshTypeName" value=""
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-2"></label>

                                    <div class="col-sm-10">
                                        <button type="button" class="btn btn-primary" onclick="refreshTable()">查询
                                        </button>
                                        <button type="reset" class="btn btn-default">重置</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <div class="row">
        <div class="col-md-4">
            <section class="tile">
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContent">
                    <#include "table.ftl"/>
                    </div>
                </div>
            </section>
        </div>

        <div class="col-md-8">

            <section class="tile">
                <div id="showMessage"><#include "../../message.ftl" /></div>
                <div class="form-horizontal">
                    <form id="search_codeInfo_table" action="${absoluteContextPath}/system/codeInfo/list" method="post">
                    </form>
                </div>
                <div class="tile-header">
                    <h1>
                    <@security.authorize ifAnyGranted="ROLE_CODE_A">
                        <button type="button" class="btn btn-green" onclick="popAddOrModifyInfo();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
                    </@security.authorize>
                    <@security.authorize ifAnyGranted="ROLE_CODE_D">
                        <button type="button" class="btn btn-cyan" onclick="deleteCodeInfo();"><i
                                class="fa fa-trash-o"></i><span class="margin-left-5">删除</span></button>
                    </@security.authorize>
                    </h1>
                </div>
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContents">
                    <#include "../codeInfo/table.ftl"/>
                    </div>
                </div>
            </section>
        </div>
    </div>

</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
</div>
</body>
</html>
